import {MessageBox, Loading} from 'element-ui'
export const WConfirm = (msg, success, error) => {
  MessageBox.confirm(msg, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(success).catch(() => {
    error && error()
  })
}

export const LoadingUtil = (options={
  lock: true,
  text: 'Loading',
  spinner: 'el-icon-loading',
  background: 'rgba(0, 0, 0, 0.7)'
}) => {
  return Loading.service(options);
}

export const makeRandomStr = (length) => {
  var result           = '';
  var characters       = 'abcdefghijkmnopqrstuvwxyz0123456789';
  var charactersLength = characters.length;
  for ( var i = 0; i < length; i++ ) {
     result += characters.charAt(Math.floor(Math.random() * charactersLength));
  }
  return result;
}

export const checkPhone = (phone) => {
  return /^1[1-9]\d{9}$/.test(phone)
}